package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 订单表
 */
@Mapper
public interface OrderMapper {
    /**
     * 新增订单
     * @param orders
     */
    void insertOrder(Orders orders);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据订单号查询当前用户的订单
     * @param
     * @param userId
     * @return
     */
    @Select("select * from sky_take_out.orders where number = #{number} and user_id = #{userId}")
    Orders getByNumberAndUserId(String number, Long userId);

    /**
     * C端-分页查询历史订单
     *
     * @return
     */
    Page<OrderVO> SelectHistoryOrdersByPage(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * C端-根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from sky_take_out.orders where id = #{id}")
    Orders getOrderById(Long id);

    /**
     * 获取各个状态订单数量
     * @param
     * @param
     * @return
     */
    Integer getOrderByStatus(Integer status);

    /**
     * 每日营业额统计
     * @param
     * @param
     * @return
     */
    Double sumTurnoverByDate(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 订单数统计
     * @param map
     * @return
     */
    Integer orderCountListByMap(Map<String, Object> map);

    /**
     * top10统计
     * @param
     * @param
     * @param
     * @return
     */
    List<GoodsSalesDTO> SalesTop10(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    /**
     * 当日营业额统计
     * @param map
     * @return
     */
    Double SumAmountByMap(Map<String, Object> map);

    /**
     * 当日有效订单数统计
     * @param map
     * @return
     */
    Integer CountOrdersByMap(Map<String, Object> map);
}
